package com.bw.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bw.entity.User;
import com.bw.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 飓风微尘
 * @since 2022-05-01
 */
@RestController
@RequestMapping("user")
@CrossOrigin
public class UserController {

    @Autowired
    IUserService userService;

    @RequestMapping("list")
    public ResponseEntity list(int currentPage, int pageSize){
        Page<User> page =userService.listWithRole(currentPage,pageSize);
        return new ResponseEntity(page,HttpStatus.OK);
    }

    @RequestMapping("add")
    public ResponseEntity add(@RequestBody  User user){
        userService.add(user);

        return new ResponseEntity(HttpStatus.OK);
    }

    @RequestMapping("update")
    public ResponseEntity update(@RequestBody User user){
        userService.updateWithRole(user);
        return new ResponseEntity(HttpStatus.OK);
    }

    @RequestMapping("del")
    public ResponseEntity update(Integer uid){
        userService.del(uid);
        return new ResponseEntity(HttpStatus.OK);
    }



}
